package com.wolfcode.goods.controller;

import com.wolfcode.common.annotation.Log;
import com.wolfcode.common.core.controller.BaseController;
import com.wolfcode.common.core.domain.AjaxResult;
import com.wolfcode.common.core.page.TableDataInfo;
import com.wolfcode.common.enums.BusinessType;
import com.wolfcode.common.utils.poi.ExcelUtil;
import com.wolfcode.goods.domain.Goods;
import com.wolfcode.goods.domain.vo.GoodsVo;
import com.wolfcode.goods.service.IGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.List;

/**
 * 物品信息Controller
 * 
 * @author wolfcode
 * @date 2022-12-10
 */
@RestController
@RequestMapping("/goods/goods")
public class GoodsController extends BaseController
{
    @Autowired
    private IGoodsService goodsService;

    /**
     * 查询物品信息列表
     */
    @PreAuthorize("@ss.hasPermi('goods:goods:list')")
    @GetMapping("/list")
    public TableDataInfo list(GoodsVo goodsVo)
    {
        startPage();
        List<Goods> list = goodsService.selectGoodsList(goodsVo);
        return getDataTable(list);
    }

    /**
     * 获取物品信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('goods:goods:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(goodsService.selectGoodsById(id));
    }

    /**
//     * 新增物品信息
//     */
//    @PreAuthorize("@ss.hasPermi('goods:goods:add')")
//    @Log(title = "物品信息", businessType = BusinessType.INSERT)
//    @PostMapping
//    public AjaxResult add(@RequestBody GoodsVo goodsVo) throws IOException,InvalidKeyException, NoSuchAlgorithmException{
//        return toAjax(goodsService.insertGoods(goodsVo));
//    }



    /**
     * 删除物品信息
     */
    @PreAuthorize("@ss.hasPermi('goods:goods:remove')")
    @Log(title = "物品信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(goodsService.deleteGoodsByIds(ids));
    }
}
